package com.onec.service.unsafe.queue;

import java.util.concurrent.ArrayBlockingQueue;

/**
 * 数组阻塞队列 : 实现生产者和消费者的数据缓存区
 */
public class ArrayBlockingQueueData {


  static class DataBuffer<T> {

    private ArrayBlockingQueue<T> arrayBlockingQueue = new ArrayBlockingQueue(10);

    public void add(T t) {
      arrayBlockingQueue.add(t);
    }

    public T fetch() throws InterruptedException {
      return arrayBlockingQueue.take();
    }
  }
}
